// json_api.h
#pragma once
#include <ArduinoJson.h>
#include "typedefine.h"

#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)

class JsonAPI
{
public:
    // 基础设备状态
    static String deviceStatus(bool online, float voltage)
    {
        JsonDocument doc; // 修改点1
        doc["type"] = "status";
        doc["device"] = DEVICE_ID;
        doc["online"] = online;
        doc["voltage"] = round(voltage * 100) / 100.0;
        return serializeToString(doc);
    }

private:
    static String serializeToString(const JsonDocument &doc)
    {
        String output;
        serializeJson(doc, output);
        return output;
    }

    static String getCallStack()
    {
        return "[" __FILE__ ":" TOSTRING(__LINE__) "]";
    }
};